package org.cangku.controller;

import org.cangku.dao.SpecialDao;
import org.cangku.entity.Special;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/special")
public class SpecialController {
    @Autowired
    private SpecialDao specialDao;

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(String name, int typeid, int sbrand, int offset, int limit){
        Map<String,Object> map = new HashMap<String, Object>();

        map.put("rows",specialDao.query(name,typeid,sbrand,offset,limit));
        map.put("total",specialDao.getCountByTJ(name,typeid,sbrand));

        return map;
    }
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String,Object> insert(Special special){
        Map<String,Object> map = new HashMap<String, Object>();
        int i = specialDao.selectBysID((int)special.getSid());
        if(i>0){
            specialDao.updateByTJjine((int)special.getSid(),special.getSpMoeny());
        }else{
            specialDao.insert(special);
        }
        return map;
    }

    /*销售页面的查询*/
    @RequestMapping("/queryinfo")
    @ResponseBody
    public Map<String,Object> queryInfo(int sid){
        Map<String,Object> map = new HashMap<String, Object>();
        int i = specialDao.selectBysID(sid);
        if(i>0){
            Special special = specialDao.queryInfo(sid);
            map.put("special",special);
            map.put("flag",true);
        }else{
            map.put("flag",false);
        }
        return map;
    }
}
